package cn.itsource.basic.util;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Description:
 * @Author: ZHl
 * @Date: 2022-09-11 14:44
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AjaxResult {

    /**
     * 状态码
     */
    @ApiModelProperty(value = "状态码")
    private String code = Constant.SYSTEM_SUCCESS;

    /**
     * 成功或者失败  成功：true  失败：false
     */
    @ApiModelProperty(value = "成功或者失败  成功：true  失败：false")
    private Boolean success = true;

    /**
     * 描述
     */
    @ApiModelProperty(value = "描述")
    private String message = "操作成功";

    /**
     * 数据
     */
    @ApiModelProperty(value = "数据")
    private Object data;


    /**
     * 返回成功   不携带数据
     * @return  AjaxResult
     */
    public static AjaxResult createSuccess(){
        return new AjaxResult();
    }

    /**
     * 返回成功   携带数据
     * @return  AjaxResult
     */
    public static AjaxResult createSuccess(Object data){
        return new AjaxResult(Constant.SYSTEM_SUCCESS,true,"操作成功",data);
    }

    /**
     * 返回失败
     * @return  AjaxResult
     */
    public static AjaxResult createError(String code,String message){
        return new AjaxResult(code,false,message,null);
    }

    /**
     * 返回失败   默认是系统异常
     * @return  AjaxResult
     */
    public static AjaxResult createError(String message){
        return AjaxResult.createError(Constant.SYSTEM_ERROR,message);
    }


}
